#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

int characterReplacement(string s, int k) {
    int res = 0;
    vector<int> cnt(26);
    auto check = [&]()->bool {
        int nmax = 0, sum = 0;
        for (int i = 0; i < 26; i++)
        {
            nmax = max(nmax, cnt[i]);
            sum += cnt[i];
        }
        return sum - nmax <= k;
    };

    for (int l = 0, r = 0; r < s.size(); r++)
    {
        cnt[s[r] - 'A']++;
        while (!check())
            cnt[s[l++] - 'A']--;
        res = max(res, r - l + 1);
    }
    return res;
}

int main()
{
    characterReplacement("ABAB", 2);
    return 0;
}